<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript">
    //配置信息验证接口（填写的js-sdk获取的签名包的参数）
    wx.config({
        debug: false,
        appId: '<?php echo $signPackage["appId"];?>',
        timestamp: '<?php echo $signPackage["timestamp"];?>',
        nonceStr: '<?php echo $signPackage["nonceStr"];?>',
        signature: '<?php echo $signPackage["signature"];?>',
        jsApiList: [
            // 所有要调用的 API 都要加到这个列表中
            'addCard'
        ]
    });
    wx.ready(function(){
        //添加卡券
        document.querySelector('#addCard').onclick = function () {
            wx.addCard({
                cardList: [
                    {
                        cardId: "",//微信公众号内创建的会员卡的id
                        cardExt: '{"timestamp":"<?php echo $huiyuanPackage['timestamp'] ?>","signature":"<?php echo $huiyuanPackage['signature'] ?>"}'//会员卡的签名包
                    }
                ],

                //成功之后的回调的函数(通过回调函数该表数据库是否领取会员卡的状态)
                success: function (res) {
                    $.ajax({
                        url: '__CONTROLLER__/editHuiYuan',
                        type: 'post',
                        dataType: 'json',
                        data: {is_LingQu: '1',user_id:"<?php echo $user['user_id'] ?>"},
                        success:function(){
                            $("#addCard").html("我的会员卡");
                        }
                    })
                }
            });
        };
    });
</script>